
import java.util.*;
import java.lang.*;

public class column {
	public String relationName="";
	private String name;
	private String type;
	public int type_total=0; //use this to evaluate the colume type;
	private LinkedList sibling =new LinkedList();
	private LinkedList child =new LinkedList();
	column(){type = "float";}	
	column(String n)
	{
		name = n;
		type = "float";
	}
	column(String n, String m)
	{
		name = n;
		type = m;
	}
	public void addsibling(Object o)
	 {
		sibling.addLast(o);
	 }
	public void addchild(Object o)
	{
		child.addLast(o);		
	}
	public void setname(String s)
	{
		name = s;
	}
	public void settype(String s)
	{
		type = s;
	}
	public String getname()
	{
		return name;
	}
	public String gettype()
	{
		return type;
	}
	public int indexofcolumn(String s) 
	//return index of column with the name s; otherwise return -1;
	{
		if (name.equals(s))
		{
			return 0;
		}else
		{
			for (int i=0; i<sibling.size();i++)
			{				
				if (((column) sibling.get(i)).getname().equalsIgnoreCase(s)) return i+1;				
			}
		}
		return -1;			
	}
	public column getcolumn(int n)
	{
		if(n==0)
		{
			return this;
		}else 
		{
			return ((column) this.sibling.get(n-1));
		}		
	}
	public int indexofchild(int s, int n)
	{
		int flag=1;
		for (int i=0; i<child.size();i++)
		{
			if (this.getchildint(i)== s )
			{
				if (flag == n)
				{
					return i;
				}else
				{
					flag++;
				}				
			}
		}//end for
		return -1;
	}
	public int indexofchild(float s, int n)
	{
		int flag=1;
		for (int i=0; i<child.size();i++)
		{
			if (this.getchildfloat(i)== s )
			{
				if (flag == n)
				{
					return i;
				}else
				{
					flag++;
				}				
			}
		}//end for
		return -1;
	}
	
	public int indexofchild(String s, int n)
	{
		int flag=1;
		for (int i=0; i<child.size();i++)
		{
			if (this.getchild(i).equalsIgnoreCase(s) )
			{
				if (flag == n)
				{
					return i;
				}else
				{
					flag++;
				}
				
			}
		}//end for
		return -1;
	}
	
	public String getchild(int n){
		return (((String) child.get(n)));
	}
	
	public int getchildint(int n)	{
		String temp = (String)child.get(n);
		if( temp!=null&&temp.equals("")){
			return 0x80000000;
		}else{
			return (int)(Double.parseDouble((String)child.get(n)));  //From double to any precision we want
		}		
	}
	public void incchild(int n){
	
		child.set(n, Integer.toString(getchildint(n)+1));
	}
	
	public void sumchild(int n, float f){
		child.set(n,Float.toString(getchildfloat(n)+f));
		
	}
	
	public void insert(int n, Object o){
		child.add(n, o);
	}
	
	public float getchildfloat(int n)	{
		String temp = (String)child.get(n);
		if( temp!=null&&temp.equals("")){
			return 0x80000000;
		}else{
			return (float)(Double.parseDouble((String)child.get(n)));  //From double to any precision we want
		}		
	}
	
	public int sizeofcolumn()
	{
		return sibling.size()+1;
	}
	public int sizeofchild()
	{
		return child.size();
	}
	public boolean existuple(int n, int[] index){
		int num = index.length;
		for (int j = 0; j<n;j++){
			int flag =0;
			for(int i=0; i<num; i++){
			    if (this.getcolumn(index[i]).gettype().equals("float")){
			    	if (this.getcolumn(index[i]).getchildfloat(n)==this.getcolumn(index[i]).getchildfloat(j)){
			    		flag++;
			    	}			    		
			    }else{
			    	if (this.getcolumn(index[i]).getchild(n).equalsIgnoreCase(this.getcolumn(index[i]).getchild(j))){
			    		flag++;
			    	}
			    }	
			}//end column
			if (flag == num)
				return true;
		}//end row
		return false;
	}
	
}
